//   判断是否为一个Promise
const isPromise = (promise) =>
  typeof promise === "object" &&
  typeof promise.then === "function" &&
  typeof promise.catch === "function";

const pa = new Promise((resolve, reject) => resolve(10));
// console.log(pa.__proto__ === Promise);

const createGetter = (isShallow = false, isReadonly = false) => {
  return function get(target, key, recevire) {
    if (!isReadonly) {
      return target;
    } else {
      return true;
    }
  };
};

const createSetter = (isShallow = false) => {
  return function set(target, key, value) {
    const oldValue = target[key];
    if (!isShallow) {
      oldValue.value = value;
      return true;
    } else {
      target[key] = value;
    }
  };
};

const readonly = {
  get: createGetter(false, false),
  set: (target, key) => {
    if (process.env.NODE_ENV === "development") {
      console.warn(`[development] the ${target}中的${key} 不可修改！`);
      // 直接return false 即可
      return true;
    }
  },
};

